package TreeSet;

import com.sun.source.tree.Tree;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Set<Integer> ints = new TreeSet<>();
        //TreeSet 有序 无索引 无重复
        //对于Doule Integer 等类型 默认从大到小 升序排序
        //对于String类型则通过首字母编码进行排序
        ints.add(10);
        ints.add(10);
        ints.add(9);
        ints.add(2);
        System.out.println(ints);
        Set<Double> doubles = new TreeSet<>();
        doubles.add(10.0);
        doubles.add(9.9);
        doubles.add(1.2);
        System.out.println(doubles);

        Set<String> strings = new TreeSet<>();
        strings.add("Java");
        strings.add("Java");
        strings.add("C++");
        strings.add("C++");
        strings.add("Python");
        strings.add("about");
        strings.add("卧槽");
        System.out.println(strings);

        Set<Apple> apples = new TreeSet<>(new Comparator<Apple>() {
            @Override
            public int compare(Apple o1, Apple o2) {
                return -(o1.getWeight()-o2.getWeight());
            }
        });
        apples.add(new Apple("红富士","红",13,15));
        apples.add(new Apple("蓝富士","蓝",14,16));
        System.out.println(apples);

    }
}
